import Vue from "vue"
import vuex from 'vuex'

Vue.use(vuex)

export default new vuex.Store({
	state: {
		userInfo: {},
		session_key: '',
		maplocation:{
			province:'广西壮族自治区',
			city:''
		},
		maplocationtemp:{
			province:'广西壮族自治区',
			city:''
		},
		vuex_mapid:0,
		vuex_address:'',
		vuex_lng: '',
		vuex_lat: '',
		dataloaded:false,
		regionlist:[],
		// regletters:[],
		vuex_showdg:0,
		vuex_joinShow:false,
		vuex_shopid:0,
		isGrayFilter: false,
		
		vuex_stall_adinfo:{},
		vuex_stall_id:0,
	},
	mutations: {
		// 设置用户信息
		setUserInfo(state, userInfo) {
			state.userInfo = userInfo
		},
		// 设置key
		setSessionKey(state, key) {
			state.session_key = key
		},
		//设置临时城市
		settempcity(state, locationinfo) {
			state.maplocationtemp = locationinfo
		},
		//设置城市
		setcity(state, locationinfo) {
			state.maplocation = locationinfo
		},
		//重置总部
		resetcity(state) {
			state.maplocation.province = '广西壮族自治区'
			state.maplocation.city = '南宁市'
			state.vuex_mapid = 0
			state.changeShop = 0
			state.vuex_address = ''
			state.vuex_lng = ''
			state.vuex_lat = ''
		},
		cleanMapAddress(state){
			state.vuex_mapid = 0
			state.vuex_address = ''
			state.vuex_lng = ''
			state.vuex_lat = ''
		},
		setMapAddress(state, address) {
			state.vuex_mapid = address.address_id
			state.vuex_address = address.address
			state.vuex_lng = address.lng
			state.vuex_lat = address.lat
		},
		setloaded(state) {
			state.dataloaded = true
		},
		//
		setRegionstate(state,keylist){
			state.regionlist = keylist
		},
		setdgshow(state) {
			state.vuex_showdg = 1
		},
		ocJoinShow(state,keyval) {
			state.vuex_joinShow = keyval
		},
		resetdgshow(state) {
			state.vuex_showdg = 0
		},
		changeShop(state,keyval) {
			state.vuex_shopid = keyval
		},
		setIsGrayFilter(state, value) {
			state.isGrayFilter = value;
		},
		
		//设置临时地址信息
		stall_adr_set(state, locationinfo) {
			state.vuex_stall_adinfo = locationinfo
		},
		stall_adr_reset(state) {
			state.vuex_stall_adinfo = {}
		},
		stall_setid(state, infoid) {
			state.vuex_stall_id = infoid
		},
		stall_reset(state) {
			state.vuex_stall_id = 0
		},
		//
		// setRegionLitterstate(state,keylist){
		// 	state.regletters = keylist
		// },
	},
	actions:{
		getCustomer({commit}) {
			uni.$u.api.getCustomer().then(res => {
				// this.userInfo = res;
				console.log(res)
				if(res.kflink){
					// #ifdef MP-WEIXIN
					wx.openCustomerServiceChat({
						extInfo: {url: res.kflink},
						corpId: 'ww74f7587b3f70c84d',
						success(res) {
							console.log(res)
						},
						fail(err){
							console.log(err,'err')
						},
					})
					// #endif
					
				}
				
			})
		},
		Cleanvxsid({commit}) {
			commit('stall_reset')
		},
	}
})
